#ifndef UTILS_H
#define UTILS_H


/////////////////////////////////////////////////////////////////////////////
/**
* Math functions.
*/

// Windoze XP can't handle the original MAX/MINDOUBLE's
#define MAXDOUBLE 1.0E+10
#define MINDOUBLE -1.0E+10

#define ARAD 57.29577951308232
#define TOLERANCE 1.0e-10
#define TOLERANCE_ANGLE 1.0e-8

#define PI 3.1415926535897932384626433832795


class Math
{
public:
    static int round(double v);
	static double pow(double x, double y);

    //static double abs(double v);
    //static int abs(int v);
    static double rad2deg(double a);
    static double deg2rad(double a);
    static double rad2gra(double a);
    static int findGCD(int a, int b);
    static bool isAngleBetween(double a,
                               double a1, double a2,
                               bool reversed);
    static double correctAngle(double a);
    static double getAngleDifference(double a1, double a2);
    static double makeAngleReadable(double angle, bool readable=true,
                                    bool* corrected=NULL);
    static bool isAngleReadable(double angle);
    static bool isSameDirection(double dir1, double dir2, double tol);
    static double eval(const std::string& expr, double def=0.0);

    static bool cmpDouble(double v1, double v2, double tol=0.001);

    /**
     * Evaluates a mathematical expression and returns the result.
     * If an error occured, ok will be set to false (if ok isn't NULL).
     */
	// Keep that in the header file for dynamic inclusion/exclusion.
    static double eval(const std::string& expr, bool* ok);

    static std::string doubleToString(double value, double prec);
    static std::string doubleToString(double value, int prec);
};

////////////////////////////////////////////////////////////////////////////////////

/**
* Text functions
*/

class Text
{
public:
    static std::string Text::itoa(const int i) ;
    static std::string Text::ftoa(const double f);
    static const int Text::atoi(std::string s) ;
    static const double Text::atof(std::string s) ;

};



#endif //UTILS_H
